/**
* @Author: 李晨光
* @Date: 2019/12/18
* @Version: 1.0
* @Last Modified by: 李晨光
* @Last Modified time: 2019/12/18
**/
<comment>
  # 积分明细
</comment>
<template>
  <div id="IntegrationDetail" class="p-box shop-detail">
    <div class="p-return">
      <mu-appbar color="primary" class="lan-header" style="box-shadow:none">
        <mu-button icon slot="left" v-close>
          <i class="iconfont angle-left iconangle-left"></i>
          <span class="lan-header-back">返回</span>
        </mu-button>积分明细
        <mu-button icon slot="right" @click="showFilter">
          <!-- <mu-icon value="more"></mu-icon> -->
          <i class="iconfont iconshaixuan4"></i>
        </mu-button>
      </mu-appbar>
    </div>
    <div class="p-content">
      <div class="top">
        <div class="content-header">
          <span>总分：</span>
          <span>{{totalScore}}</span>
        </div>
        <div class="content-sta">
          <span>{{currentDate}}</span>
          <span>积分:{{currentTotal}}积分</span>
        </div>
      </div>
      <div class="content" ref="container">
        <mu-load-more
          v-if="data.length"
          @refresh="refresh"
          :refreshing="refreshing"
          :loading="loading"
          @load="load"
          :loaded-all="loadAll"
        >
          <!-- 这里是业务结构 -->
          <div class="ibox" v-for="(item,index) in data" :key="index">
            <div class="ibox-title">
              <span class="title primary" v-if="item.type=='1'">行为观察</span>
              <span class="title success" v-else>问题上报</span>
              <span class="text">+{{item.score}}</span>
            </div>
            <div class="ibox-content">
              <!-- 行为观察 -->
              <ul class="ul" v-if="item.type=='1'">
                <li class="li">
                  <span class="label">审批时间：</span>
                  <span class="detail">{{item.approvalTime}}</span>
                </li>
                <li class="li">
                  <span class="label">质量工匠行为：</span>
                  <span class="detail">{{item.behaviorName}}</span>
                </li>
              </ul>
              <!-- 问题上报 -->
              <ul class="ul" v-else>
                <li class="li">
                  <span class="label">审批时间：</span>
                  <span class="detail">{{item.approvalTime}}</span>
                </li>
                <li class="li">
                  <span class="label">地点：</span>
                  <span class="detail">{{item.areaName}}</span>
                </li>
                <li class="li">
                  <span class="label">质量问题描述：</span>
                  <span class="detail">{{item.problemDesc}}</span>
                </li>
              </ul>
            </div>
          </div>
          <p v-if="loadAll" class="nodataTips">无更多数据了</p>
        </mu-load-more>
        <NoData v-if="!data.length&&!listLoading" />
      </div>
    </div>
    <DateFilter ref="DateFilter" @searchList="initPage" />
  </div>
</template>

<script>
import DateFilter from "@/dateFilter/DateFilter.vue";
export default {
  name: "IntegrationDetail",
  components: {
    DateFilter
  },
  props: {},
  data() {
    return {
      timeObj: {
        startTime: "",
        endTime: ""
      },
      listLoading: false,
      totalScore: 0,
      leftScore: 0,
      currentDate: "9月",
      currentTotal: 0,
      refreshing: false,
      loading: false,
      loaded: false,
      loadAll: false,
      pageSize: 10,
      pageNo: 0,
      totalPage: 1,
      params: {},
      data: []
    };
  },
  computed: {},
  created() {
    let date = new Date();
    let D = new Date().getDate();
    let M = date.getMonth() + 1;
    D = D < 10 ? "0" + D : D;
    M = M < 10 ? "0" + M : M;
    let form = {
      startTime: date.getFullYear() + "-" + M + "-" + "01",
      endTime: date.getFullYear() + "-" + M + "-" + D
    };
    this.initTotal();
    this.initPage(form);
  },
  mounted() {},
  watch: {},
  methods: {
    showFilter() {
      this.$refs.DateFilter.init();
    },
    initPage(form) {
      if (!form.startTime && !form.endTime) {
        this.currentDate = "所有时间";
      } else if (form.startTime && form.endTime) {
        this.currentDate = form.startTime + "至" + form.endTime;
      } else if (form.startTime && !form.endTime) {
        this.currentDate = form.startTime + "以后";
      } else if (!form.startTime && form.endTime) {
        this.currentDate = form.endTime + "以前";
      }
      this.params = {
        orgId: this.$A.GS("orgInfo")["orgId"],
        type: this.$A.GS("orgInfo")["type"],
        startTime: form.startTime,
        endTime: form.endTime,
        userId: this.$A.GS("userInfo")["userId"]
      };
      this.$nextTick(() => {
        this.refresh();
      });
    },
    //获取当前人的总积分
    initTotal() {
      this.$A
        .Go("get", "/safety/userScore/myScore", {
          userId: this.$A.GS("userInfo")["userId"]
        })
        .then(res => {
          this.$closeLoading();
          if (res.code == 200) {
            if (res.body) {
              this.totalScore = res.body.totalScore;
            }
            // this.form.pointList = array;
          } else {
          }
        });
    },
    async refresh() {
      this.refreshing = true;
      this.pageNo = 0;
      this.totalPage = 1;
      this.loaded = false;
      this.loadAll = false;
      this.data = [];
      this.$refs.container.scrollTop = 0;
      this.getCurrentTotal();
      this.initTotal();
      await this.getData();
      this.refreshing = false;
    },
    async load() {
      this.loading = true;
      await this.getData();
      this.loading = false;
    },
    async getData() {
      if (this.pageNo >= this.totalPage) {
        this.loadAll = true;
        return;
      }

      this.$openLoading();
      if (!this.loadAll) {
        this.pageNo += 1;
      } else {
        return;
      }
      let obj = {
        current: this.pageNo,
        size: this.pageSize
      };
      let params = Object.assign(obj, this.params);
      this.listLoading = true;
      this.$A.Go("get", "/safety/shop/myScore/detail", params).then(
        success => {
          if (success.code == 200) {
            let data = success.body.rows || [];
            let total = success.body.page.rows || "0";
            this.totalPage = Math.ceil(total / this.pageSize);
            // let data =  []
            // let total = 0
            if (this.pageNo == 1) {
              this.data = data;
            } else {
              this.data.push(...data);
            }
            if (
              total == 0 ||
              Math.ceil(total / this.pageSize) <= this.pageNo ||
              data.length <= 0
            ) {
              this.loadAll = true;
            }
          } else {
            this.data = [];
          }
          this.loaded = true;
          this.$closeLoading();
          this.listLoading = false;
        },
        err => {
          this.$closeLoading();
          console.warn(err);
          this.listLoading = false;
        }
      );
    },
    //获取查询条件下的总积分
    getCurrentTotal() {
      this.$A
        .Go("get", "/safety/shop/myScore/totalScore", this.params)
        .then(res => {
          if (res.code == 200) {
            if (res.body) {
              this.currentTotal = res.body.totalScore;
            }
            // this.form.pointList = array;
          } else {
          }
        });
    }
  },
  destroyed() {}
};
</script>

<style lang="scss">
#IntegrationDetail {
  .lan-nodata {
    height: 100%;
  }
}
</style>
